package com.ryder.book_cycle.enums;

import lombok.Getter;

/**
 * 描述: 响应结果枚举
 *
 * @author Ryder
 * @version 1.0
 * @date 2025/02/03
 * @since 1.0 // 版本号，指明从哪个版本开始
 */
@Getter
public enum ResultCodeEnum {

    SUCCESS(200, "成功"),
    NOT_FOUND(404, "请求的资源不存在"),
    FAIL(500, "服务器异常，请稍后重试");

    private final int code;
    private final String desc;

    ResultCodeEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static ResultCodeEnum getByCode(int codeVal) {
        for (ResultCodeEnum resultCodeEnum : ResultCodeEnum.values()) {
            if (resultCodeEnum.getCode() == codeVal) {
                return resultCodeEnum;
            }
        }
        return null;
    }
}
